/**
 * author: zhou
 * date: 2017.10.18
 * description: mongodb 连接核心文件
 * 
 */

// 引入mongoose
const   mongoose = require('mongoose'),
        { mongoOptions } = require('config-lite')(__dirname);

mongoose.Promise = global.Promise;
mongoose.connect(mongoOptions.url, mongoOptions.options);

// mongodb连接实例
const db = mongoose.connection;
db.once('open', () => {
    console.log('students-server connect mongo successfully');
});
db.on('error', (error) => {
    console.log('students-server connect mongo failed...');
    console.log(`mongo connect error: ${error}`);
});

module.exports = db;
